//
//  AdVideoVC.swift
//  LeGou
//
//  Created by lxm on 2022/8/31.
//

import UIKit

class AdVideoVC: ZMViewController {
    //MARK: --------------------属性--------------------
    var url = ""
    //MARK: --------------------UI控件--------------------
    let palyerView = PlayerView()
    
    let closeBtn = UIButton().then { b in
        b.setTitle("关闭", for: .normal)
        b.setTitleColor(.white, for: .normal)
    }
    //MARK: --------------------生命周期--------------------
    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
        addConstraints()
        bindAction()
    }
    //MARK: --------------------UI--------------------
    func setUI() {
        title = ""
        view.addSubview(palyerView)
        hbd_barHidden = true
        play()
        view.backgroundColor = .black
        
        view.addSubview(closeBtn)
    }
    
    func addConstraints() {
        palyerView.snp.makeConstraints { make in
            make.edges.equalTo(view.safeAreaLayoutGuide)
        }
        
        closeBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-16)
            make.top.equalTo(view.safeAreaLayoutGuide).offset(16)
        }
    }
//    "http://legohui.oss-cn-beijing.aliyuncs.com/crmebimage/public/content/2022/08/30/c728e92c33014145a3720725dd8d71750d6588rkg3.mp4"
    func play() {
        let avpsource = AVPUrlSource()
        avpsource.url(with: url)
        palyerView.play(source: avpsource)
        
    }
    
    //MARK: --------------------methods--------------------
    func bindAction() {
        closeBtn.rx.tap.subscribe(onNext:{ [unowned self] resp in
            self.navigationController?.popViewController(animated: true)
        }).disposed(by: disposeBag)
    }

    //MARK: --------------------delegate--------------------
}
